import os
from django.test import TestCase

class ReadWriteMessagingTest(TestCase):
    def test_write_message_2_view(self):
        from utils import Messaging

        v2v = Messaging('/tmp/test.msg')

        expected = v2v.set([
            {'type': 'success', 'message': 'msg content1'},
            {'type': 'error', 'message': 'msg content2'}
        ])

        self.assertEqual(expected, True)

    def test_read_message_2_view(self):
        from utils import Messaging

        v2v = Messaging('/tmp/test.msg')
        self.assertEqual(len(v2v.get()), 2)

    def test_read_message_2_view_with_removal(self):
        from utils import Messaging
        tempfile = '/tmp/test.msg'
        v2v = Messaging(tempfile)
        v2v.get(remove=True)

        self.assertTrue(not os.path.exists('/tmp/test.msg'))
